﻿@model List<NFine.Domain._03_Entity.Weixin.Company_FileEntity>
@{
    Layout = null;
    List<NFine.Domain._03_Entity.Weixin.Company_FileTypeEntity> typeList = null;
    if (ViewData["cateList"] != null)
    {
        typeList = (List<NFine.Domain._03_Entity.Weixin.Company_FileTypeEntity>)ViewData["cateList"];
    }
}

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>文件列表</title>
    <link rel="stylesheet" href="//cdn.bootcss.com/jquery-weui/1.0.1/css/jquery-weui.min.css">
    <link rel="stylesheet" href="//cdn.bootcss.com/weui/1.1.1/style/weui.min.css">
    <link href="~/Content/M/css/swiper.css" rel="stylesheet" />
    <link href="~/Content/M/css/list.css" rel="stylesheet" />
</head>

<body>
    <div style="position:fixed; height:2.2rem; top:0px; left:0px; width:100%; z-index:2">
        <div id="exctype" class="swiper-container">
            <div class="swiper-wrapper" style='transform:translate3d(@Html.Raw("-"+((int)ViewData["indexId"])*92.52+"px"), 0px, 0px)'>
                <div id="div_0" index="0" class="swiper-slide">全部</div>
                @{
                    if (typeList != null)
                    {
                        for (var i = 0; i < typeList.Count; i++)
                        {
                            <div id="div_@typeList[i].Id" class="swiper-slide" index="@Html.Raw(i>2?(i+1):0))">@typeList[i].TypeName</div>
                        }
                    }
                }
                <div class="swiper-slide"></div>
            </div>
        </div>
        <div class="weui-search-bar" id="searchBar" style="display:none;position:absolute;left:0;top:0;width:100%;z-index:10;">
            <form class="weui-search-bar__form" action="FileIndex">
                <div class="weui-search-bar__box">
                    <i class="weui-icon-search"></i>
                    <input type="hidden" value="@ViewData["cateId"]" name="cateId" />
                    <input type="hidden" value="@ViewData["indexId"]" name="indexId" />
                    <input type="search" name="searchInput" class="weui-search-bar__input" id="searchInput" placeholder="搜索" required="">
                    <a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
                </div>
                <label class="weui-search-bar__label" id="searchText">
                    <i class="weui-icon-search"></i>
                    <span>搜索</span>
                </label>
            </form>
            <a href="javascript:" class="weui-search-bar__cancel-btn" id="searchCancel">取消</a>
        </div>
        <div id="searchbtn" style="position:absolute;right:0;top:0; width:2.2rem;z-index:9;height: 100%; text-align:center; background-color:#efeff4;">
            <i class="weui-icon-search" style="font-size:1.2rem; margin-top:.4rem; color:white;"></i>
        </div>
    </div>

    <div style="height:100%" id="divContent">
        @*在没有搜索参数时，该内容不显示*@
        <div style="font-size:.7rem; margin-top:2.5rem; background-color:white; padding:.5rem;" id="divSearch" hidden>
            搜索关键字：<span style="color:#ff6a00;">@ViewData["search"]</span>
            <a href="javascript:clearSearch();"><i class="weui-icon-cancel"></i></a>
        </div>
        <div style='@Html.Raw(ViewData["search"].ToString()!=""?"margin-top:0.3rem":"margin-top:2.3rem")' >
            <div class="weui-panel weui-panel_access" style="margin-top:auto" id="divFile">
                @{
                    if (Model != null && Model.Count > 0)
                    {
                        <div class="weui-panel__bd">
                            @foreach (var com in Model)
                            {
                                var strpath = (int)ViewData["isPay"] == 1|| com.IsPay == 0 ||com._HaveBuy==1 ? "javascript:location.href='" + com.FilePath +"'": "openPay("+com.PayMoney+","+com.Id+")";
                                <a onclick="@strpath" class="weui-media-box weui-media-box_appmsg" style="padding:10px 5px 10px 10px;">
                                    <div class="weui-media-box__hd" style="width:100px;height:100px">
                                        <img class="weui-media-box__thumb" src="@com.FileImage" style="width:100%;height:100%" />
                                    </div>
                                    <div class="weui-media-box__bd">
                                        <h4 class="weui-media-box__title" >@com.FileName</h4>
                                        <div class="weui-media-box__desc" style="line-height:1.6;-webkit-line-clamp:3">@com.FileDescribe</div>
                                        <div class="weui-media-box__desc" style="line-height:1.6">@com.CreatDate 
                                            @if (com.IsPay == 1)
                                            {
                                                <label style="color:red;float:right; font-size:0.7rem;margin-right:0.2rem">
                                                    @Html.Raw("￥" + com.PayMoney)
                                                   @if((int)ViewData["isPay"] == 0 && com._HaveBuy == 1)
                                                   {
                                                       @:(已购)
                                                   }
                                                </label>
                                            }
                                            else
                                            {
                                                <label style="color:green;float:right;margin-right:0.2rem ">
                                                    免费
                                                </label>
                                            }
                                        </div>
                                    </div>
                                </a>
                            }
                        </div>
                    }
                    else
                    {
                        <div style="text-align:center;margin:0.5rem auto">
                            暂无文件
                        </div>
                    }
                }
            </div>
        </div>
       @if (Model.Count == 10)
        {
            <div class="weui-loadmore" id="divMore">
                <i class="weui-loading"></i>
                <span class="weui-loadmore__tips">上拉加载更多</span>
            </div>
          
       }
       else
       {
           <div class="weui-footer" style="margin-top:0.5rem">--加载完毕--</div>
        }
     
        @if ((int)ViewData["isPay"] == 0)
        { <div style="height:3rem;" id="divFoot"></div>}
    </div>
   
    <div id="divPay" style="height:2.5rem; position:fixed; bottom:0px;width:100%; left:0; text-align:center;  line-height:2.5rem;" hidden >
            <div style="width:100%;">
                <a onclick="pay(0,@ViewData["PayMoney"])" class="weui-btn weui-btn_primary" style="height:2.5rem;" id="btnPay">
                    开通会员 <i class="weui-loading"  ></i>
                </a>
            </div>
    </div>

    <script src="//cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
    <script src="//cdn.bootcss.com/jquery-weui/1.0.1/js/jquery-weui.min.js"></script>
    <script src="//cdn.bootcss.com/jquery-weui/1.0.1/js/swiper.min.js"> </script>
    <script src="~/Content/M/js/fastclick.js"></script>
    <script type="text/javascript">
        FastClick.attach(document.body);
        var exctype = new Swiper('#exctype', {
            spaceBetween: 3,
            //visiblilityFullfit: true,
            slidesPerView: 3.8,
            freeMode: true
        });
        //上拉加载更多
        var loading = false;  //状态标记
        var _page = 0;

        $(document).ready(function () {
            $("#btnPay .weui-loading").hide();
            if(@ViewData["isPay"]==0)
            {
                $("#divPay").show();
            }
            $("#searchbtn").click(function () {
                $("#searchBar").show().addClass("weui-search-bar_focusing");
            });
            $("#searchCancel").click(function () {
                $("#searchBar").hide();
            });

            $("#div_@ViewData["cateId"]").addClass("active");


            if("@ViewData["search"]"!="")
            {
                $("#divSearch").show();
            }

            $("#exctype .swiper-slide").click(function () {
                location.replace("FileIndex?cateId=" + $(this).attr("id").substr(4) + "&indexId=" + $(this).attr("index"));
            });
            if (@Model.Count == 10)
             {   $(document.body).infinite().on("infinite", function () {
                    if (loading) return;
                    loading = true;
                    setTimeout(function () {
                        _page++;
                        initMoreData();
                        loading = false;
                    }, 1000);
             });
            }
        });
        function initMoreData() {
            $.ajax({
                url: "/Companys/getMoreFile?cateId=@ViewData["cateId"]&start=" + _page + "&searchInput=@ViewData["search"]",
                dataType: 'json',
            type: 'post',
            success: function (_data) {
                var _html = '';

                for (var i = 0, len = _data.length; i < len; i++) {
                    var file = _data[i];
                    var strpath = @ViewData["isPay"] == 1|| file.IsPay == 0||file._HaveBuy==1 ? "javascript:location.href='" + file.FilePath +"'": "openPay("+file.PayMoney+","+file.Id+")";
                    _html+=' <a onclick="'+strpath+'" class="weui-media-box weui-media-box_appmsg" style="padding:10px 5px 10px 10px;">';
                    _html+=' <div class="weui-media-box__hd" style="width:100px;height:100px">';
                    _html+='<img class="weui-media-box__thumb" src="'+file.FileImage+'" style="width:100%;height:100%" />';
                    _html+='</div> <div class="weui-media-box__bd">';
                    _html+=' <h4 class="weui-media-box__title">'+file.FileName+'</h4>';
                    if(file.FileDescribe==null)
                        file.FileDescribe="";
                    _html+=' <div class="weui-media-box__desc" style="line-height:1.6;-webkit-line-clamp:3">'+file.FileDescribe+'</div>';
                    _html+=' <div class="weui-media-box__desc" style="line-height:1.6">'+file.CreatDate;
                    if (file.IsPay == 1)
                    {
                        _html+=' <label style="color:red;float:right; font-size:0.7rem;margin-right:0.2rem">￥'+ file.PayMoney;
                        if(@ViewData["isPay"] == 0 && file._HaveBuy == 1)
                        {
                            _html+=' (已购)';
                        }
                        _html+='</label>';
                    }
                    else
                    {
                        _html+=' <label style="color:green;float:right;margin-right:0.2rem ">免费 </label>';
                    }
                    _html+='</div></div></a>';
                }
                $("#divFile").append(_html);

                if (_data.length <10) {
                    $(document.body).destroyInfinite();
                    $("#divMore").hide();
                    _html='<div class="weui-footer" style="margin-top:0.5rem">--加载完毕--</div>';
                    if (@ViewData["isPay"] == 1)
                    {
                        $("#divContent").append(_html+'<div style="height:1rem;" id="divFoot"></div>');
                    }else{
                        $("#divFoot").before(_html);
                    }
                }
            }
        });
        }
        function clearSearch() {
            location.replace('FileIndex?cateId=@ViewData["cateId"]&indexId=@ViewData["indexId"]');
        };
        //支付
        function pay(FileId,money) {
            $("#btnPay .weui-loading").show();
            $.ajax({
                url: "/Companys/pay?FileId="+FileId+"&money="+money,
                dataType: 'text',
            type: 'post',
            success: function (_data) {

                if (_data.indexOf("SUCCESS") != -1) {
                    var res =  JSON.parse(_data);
                    WeixinJSBridge.invoke(
                       'getBrandWCPayRequest',
                       res.wx,
                       function (res) {
                           if (res.err_msg == "get_brand_wcpay_request:ok") {
                               $.toptip('支付成功');
                               location.replace('FileIndex?cateId=@ViewData["cateId"]&indexId=@ViewData["indexId"]');
                           }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                           else if (res.err_msg == "get_brand_wcpay_request:fail") {
                               $.toptip('支付失败', 'error');
                           }
                       }
                   );

                } else {
                    $.toptip('支付失败', 'error');
                }
                $("#btnPay .weui-loading").hide();
            }
        });
        }
        function openPay(m,f){
            $.prompt({
                title: "提示",
                onOK: function () {
                    var _obj=$("input[name='pay']:checked");
                    pay(_obj.attr("fileId"),_obj.val());
                    $("div").remove(".weui-dialog");
                },
                onCancel: function () {
                    $("div").remove(".weui-dialog");
                    //  $.closePrompt();  //点击取消
                }
            });
            $("#weui-prompt-input").remove();
            // $(".weui-dialog__bd").append('<div style="display:inline-block;"> <div style="float:left;"><img src="/Content/M/img/money_large.png"/></div><div style="float:left;color: #555;margin-top:0.9rem; margin-left:0.5rem;text-align:left;"> 您尚未支付，请先支付！</div> </div>');
            $(".weui-dialog__bd").html('<div style="color: #555;height:100px"> <div style="float:left;margin-left:1rem;margin-top:0.8rem"><input type="radio" name="pay" id="rdoOpen" value="@ViewData["PayMoney"]" fileId="0" checked /> <label for="rdoOpen">支付'+@ViewData["PayMoney"]+'元，开通会员！</label> </div>  <div style="float:left;margin-left:1rem;margin-top:1rem;"><input type="radio" name="pay" id="rdoBuy" fileId="'+f+'" value="'+m+'"/> <label for="rdoBuy">支付'+m+'元，下载该资源！</label></div> </div>');
        }
    </script>
</body>
</html>
